package org.ccay.core.server;

import java.text.MessageFormat;

import org.ccay.core.request.Application;

 
/**
 * 服务器信息VO	
 */
public class ServerInfoVO implements java.io.Serializable {

	/**
	 * @return the serverName
	 */
	public String getServerName() {
		return serverName;
	}
	/**
	 * @param serverName the serverName to set
	 */
	public void setServerName(String serverName) {
		this.serverName = serverName;
	}
	/**
	 * @return the appPort
	 */
	public int getAppPort() {
		return appPort;
	}
	/**
	 * @param appPort the appPort to set
	 */
	public void setAppPort(int appPort) {
		this.appPort = appPort;
	}
	/**
	 * @return the serverDomainName
	 */
	public String getServerDomainName() {
		return serverDomainName;
	}
	/**
	 * @param serverDomainName the serverDomainName to set
	 */
	public void setServerDomainName(String serverDomainName) {
		this.serverDomainName = serverDomainName;
	}
	
	 
	public int getServerNameHashcode() {
		return serverNameHashcode;
	}
	public void setServerNameHashcode(int serverNameHashcode) {
		this.serverNameHashcode = serverNameHashcode;
	}



	private static final long serialVersionUID = 6936678672815623346L;
	/**
	 * 服务应用名称
	 */
	private String serverName;
	/**
	 * 应用端口
	 */
	private int appPort; 
	/**
	 * 服务器域名（xxx.ccay.org）
	 */
	private String serverDomainName;
	/**
	 * 服务器hashcode的绝对值
	 */
	private int serverNameHashcode;
	
	private String serverUrl;

	/** 
	 * 判断取老配置或新的集群配置
	 * @return
	 */
	public String getServerUrl() {
		if (serverUrl != null && serverUrl.indexOf(":") != -1) {
			return serverUrl;
		} else {
			String urlPattern="{0}:{1,number,#}{2}";
			String contextPath= Application.getCurrent().getContextPath();
			//构建URL
			return MessageFormat.format(urlPattern, serverDomainName,appPort,contextPath);
		}
	}
	public void setServerUrl(String serverUrl) {
		this.serverUrl = serverUrl;
	}
	
}
